﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>

<link href="../../Content/Css/feeling.css" rel="Stylesheet" />
<script type="text/javascript" src="../../Content/ImportJs/jquery.ui.datepicker.js"></script>
<script type="text/javascript" src="../../Content/ImportJs/jquery.ui.core.js"></script>
<script type="text/javescript" src="../../Content/ImportJs/jquery.ui.widget.js"></script>
<link href="../../Content/Css/feeling.css" rel="Stylesheet" />
<link href="../../Content/Css/themes/base/jquery.ui.all.css" rel="Stylesheet" />
<script type="text/javascript">
    $(document).ready(function () {
        function DeleteFeeling(e) {
            var postdata = $(e).attr('data');
            $.ajax({
                type: 'POST',
                url: "http://" + window.location.host + "/Feeling/DeleteFeeling",
                data: { modelId: postdata },
                success: function (data) {
                    cAlert(data);
                },
                error: function () {
                    cAlert("网络不给力,请稍后重试");
                }
            });
        }


        $('#minTime').datepicker();
        $('#maxTime').datepicker();
        $('#minTime').focus();

    });
</script>
<script type="text/javascript">
    function GetFeelingComment(e) {

        var where = $(e).parents('div.trend');
        var type = 3;
        
        var id = where.attr('data');

        if (where.next('div:first').hasClass('commentlist')) return;
        $.ajax({ url: '/FriendTrend/GetCommentListJson', data: { Id: id, type: type }, dataType: 'json', type: 'post', success: function (data) {
            var html = '<div class="commentlist"><div class="commenthead"></div><div class="comment">';
            for (i in data) html = html + '<div class="tt"><div class="close"><a href="javascript:void(0);"><img src="../Content/Images/mainpage/X.png" alt="关闭"></a></div><div class="smallimagepart"><img class="smallheadimage" src="' + data[i].ImagePath + '"></div><div class="commentcontent"><div class="headline">' + data[i].Name + '  ' + data[i].CreateTime + '</div><div class="contentline">' + data[i].Content + '</div></div><div class="commentclear"></div></div>';
            html = html + '<div class="reply"><textarea class="com commentareafocusout" >按Enter发表评论……</textarea></div></div>';
            where.after(html);


            where.next('div.commentlist').find('div.reply textarea').focus(function () {
                if ($(this).val() != '按Enter发表评论……') return;
                $(this).val('').removeClass('commentareafocusout').addClass('commentareafocus');
            }).focusout(function () {
                if ($(this).val() != '') return;
                $(this).val('按Enter发表评论……').removeClass('commentareafocus').addClass('commentareafocusout');
            }).bind('keydown', function (e) {
                if (e.keyCode == 13) {
                    var comment = $(this).val();
                    var ee = $(this);
                    //begin
                    if (comment.length <= 0)
                        return;
                    if (comment.length > 140) {
                        cAlert('评论不能长于140字');
                        return;
                    }

                    $.ajax({
                        url: '/FriendTrend/AddComment',
                        type: 'POST',
                        data: { Id: id, type: type, comment: comment },
                        success: function (data) {

                            ee.val('');
                            ee.focus(1, function () { this.blur() });


                            ee.before('<div class="tt"><div class="close"><a href="javascript:void(0);"><img src="../Content/Images/mainpage/X.png" alt="关闭"></a></div><div class="smallimagepart"><img class="smallheadimage" src="' + data.ImagePath + '"></div><div class="commentcontent"><div class="headline">' + data.Name + '  ' + data.CreateTime + '</div><div class="contentline">' + data.Content + '</div></div><div class="commentclear"></div></div>').slideDown('slow');
                            where.next('div.commentlist').css('height', '0').slideDown('slow');
                            where.next('div.commentlist').find('div.close a').click(function () {
                                if ($(this).parents('div.commentlist').find('div').length == 0)
                                    $(this).parents('div.commentlist').slideUp();
                                else
                                    $(this).parents('div.tt').slideUp();
                            });
                        },
                        error: function () { Error(); }
                    });
                    //emd
                   
                }//end of if keycode
            });


            where.next('div.commentlist').css('height', '0').slideDown('slow');
            where.next('div.commentlist').find('div.close a').click(function () {
                if ($(this).parents('div.commentlist').find('div').length == 0)
                    $(this).parents('div.commentlist').slideUp();
                else
                    $(this).parents('div.tt').slideUp();
            });
        }
        });


    }



</script>